package com.ej.generics;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import java.util.TreeSet;


/**
 * Hello world!
 *
 */
public class App 
{
	public static void main( String[] args )
    {
		/* Any Object can be added using the wild card annotation*/
    	App app = new App();
    	app.print(new HashSet<String>());
    	app.print(new TreeSet<String>());
    	
    	// Only null value can be added to this type of collection
    	Collection<?> collection =  new ArrayList<String>();
    	collection.add(null);
    	
    	// Using type parameters  and favor generic methods
    	Set<String> guys = new HashSet<String>(
		Arrays.asList("Tom", "Dick", "Harry"));
		Set<String> stooges = new HashSet<String>(
		Arrays.asList("Larry", "Moe", "Curly"));
		Set<String> aflCio = add(guys, stooges);
		System.out.println(aflCio);
    }
    
    public void print(Set<?> pSet){
    	System.out.println("Size of set1"+pSet.size());
    }
    
    public static <E> Set<E> add (Set<E> s1 , Set<E> s2){
    	Set<E> s3 = new HashSet<E>(s1);
    	s3.addAll(s2);
    	return s3;
    }
    
}


